import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// Element Plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './styles/scrollbar.scss'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// HTTP请求
import request from '@/utils/request'
import http from '@/utils/http'
import api from '@/api'

const app = createApp(App)

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.config.productionTip = false

app.config.errorHandler = function (err, vm, info) {
  // 这里可以自定义错误处理逻辑，例如记录错误到服务器或使用自定义的错误报告
  console.error(`Error in ${info}:`, err);
};
// 全局注册HTTP工具
app.config.globalProperties.$http = http
app.config.globalProperties.$api = api
app.config.globalProperties.$request = request

// 提供全局属性
app.provide('$http', http)
app.provide('$api', api)
app.provide('$request', request)

app.use(store).use(router).use(ElementPlus).mount('#app')
